#include "OLPixmapWidget.h"

#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QBitmap>

OLPixmapWidget::OLPixmapWidget(const QPixmap& pixmap, QWidget *parent) :
    QWidget(parent), m_pixmap(pixmap), m_opacity(1.0)
{
    setFixedSize(m_pixmap.size());
}

OLPixmapWidget::OLPixmapWidget(const QString& pixmap, QWidget *parent)
    : QWidget(parent), m_pixmap(pixmap), m_opacity(1.0)
{
    setFixedSize(m_pixmap.size());
}

const QPixmap& OLPixmapWidget::pixmap() const
{
    return m_pixmap;
}

void OLPixmapWidget::paintEvent(QPaintEvent *e)
{
    QPainter p(this);
    p.fillRect(rect(), Qt::transparent);
    p.setOpacity(m_opacity);
    p.drawPixmap(rect(), m_pixmap);
}

void OLPixmapWidget::setOpacity(qreal opacity)
{
    m_opacity = opacity;
    update();
}

qreal OLPixmapWidget::opacity()
{
    return m_opacity;
}
